# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python

from cerbero.tools.libtool import LibtoolLibrary

class Recipe(recipe.Recipe):
    name = 'libpsl'
    version = '0.21.0'
    licenses = [{License.MIT: ['COPYING']}]
    stype = SourceType.TARBALL
    btype = BuildType.MESON
    url = 'https://github.com/rockdaboot/libpsl/releases/download/libpsl-%(version)s/libpsl-%(version)s.tar.gz'
    tarball_checksum = '41bd1c75a375b85c337b59783f5deb93dbb443fb0a52d257f403df7bd653ee12'
    meson_options = {'runtime': 'no', 'builtin': 'no'}

    patches = [
        # Taken from upstream git tag 0.21.0
        'libpsl/0001-Initial-import-of-meson-build-files-from-upstream.patch',
        # https://github.com/rockdaboot/libpsl/pull/148
        'libpsl/0001-meson-Use-libtool-library-versioning-same-as-autotoo.patch',
    ]

    files_libs = ['libpsl']
    files_devel = ['include/libpsl.h', 'lib/pkgconfig/libpsl.pc']

    def prepare(self):
        # FIXME: The actual upstreamable fix would be to not use system() at
        # all, or to have an option to disable building of tests.
        if self.config.target_platform == Platform.IOS:
            self.patches += ['libpsl/0002-meson-Do-not-build-tests-on-iOS.patch']

    def post_install(self):
        libtool_la = LibtoolLibrary('psl', 0, 0, 0, self.config.libdir,
                self.config.target_platform)
        libtool_la.save()
        super().post_install()
